<template>
	<u-radio-group style="margin-top: 30px" v-model="couponId" @change="radioGroupChange">
		<view v-for="(item, index) in props.list" :key="index" style="width: 100%">
			<view class="coupon-user-item">
				<view>
					<view class="content" @click="radioGroupChange(item.id)">
						<view class="page-group">
							<text class="fold-page"></text>
							<text class="page">{{ item.couponInfo.couponType == '1' ? '满减券' : '折扣券' }}</text>
						</view>
						<text class="dot-left"></text>
						<text class="dot-right"></text>
						<view class="coupon-detail">
							<view v-if="item.couponInfo.couponType == '2'">
								<text>{{ item.couponInfo.discount }}</text>
								<text>折</text>
							</view>
							<view v-else-if="item.couponInfo.couponType == '1'">
								<text>{{ item.couponInfo.amount }}</text>
								<text>元</text>
							</view>
							<view>
								<view style="font-size: 14px; font-weight: 700">
									{{ item.couponInfo.threshold > 0 ? '订单满' + item.couponInfo.threshold + '可以使用' : '无门槛优惠券' }}
								</view>
								<view style="font-size: 12px">{{ item.couponInfo.useRange == '1' ? '全部商品可用' : '指定商品可用' }}</view>
								<view style="font-size: 12px; color: #909090"> 有效期至{{ item.couponInfo.receiveEndedAt }} </view>
							</view>
							<view>
								<u-radio shape="circle" :name="item.id" :disabled="props.price < item.couponInfo.threshold"></u-radio>
							</view>
						</view>
					</view>
					<view style="display: flex; justify-content: center" v-if="props.price < item.couponInfo.threshold">
						{{ '订单未满' + item.couponInfo.threshold + '元,无法使用' }}</view
					>
				</view>
			</view>
		</view>
	</u-radio-group>
</template>

<script setup lang="ts">
import { watch, ref } from 'vue';
const emit = defineEmits(['confirm', 'update:couponUserId']);
const props = defineProps({
	checkedCouponId: {
		type: String,
		default: '',
	},
	list: {
		type: Array,
		default: [],
	},
	price: {
		type: Number,
		default: 0,
	},
});
const couponId = ref(props.checkedCouponId);
watch(props.checkedCouponId as any, (New: string, Old) => {
	couponId.value = New;
});
const radioGroupChange = (val: any) => {
	emit('update:couponUserId', val);
	emit('confirm', val);
};
</script>

<style lang="scss" scoped>
.coupon-user-item {
	overflow: hidden;
	margin: 10px;
	padding-left: 2px;
	position: relative;
}

.coupon-user-item > view {
	border: 1px solid #f2f2f2;
	background: #fff;
	border-radius: 10px;
}

.coupon-user-item .dot-left,
.coupon-user-item .dot-right {
	display: block;
	width: 12px;
	height: 12px;
	border-radius: 50%;
	position: absolute;
	z-index: 999;
}

.coupon-user-item .dot-left {
	bottom: -6px;
	left: -6px;
}

.coupon-user-item .dot-right {
	bottom: -6px;
	right: -6px;
}

.coupon-user-item .page-group {
	position: absolute;
	top: 10px;
	left: -2px;
	width: 100%;
	max-width: 120px;
}

.coupon-user-item .page-group .fold-page {
	display: block;
	width: 2px;
	height: 5px;
	background: #db0113;
	transform: skewY(-40deg);
	position: absolute;
	top: -1px;
	left: 0;
	z-index: 0;
}

.coupon-user-item .page-group .page {
	position: absolute;
	z-index: 1;
	display: block;
	padding: 0 10px;
	height: 20px;
	background: linear-gradient(137deg, #ff5b5b 0%, #db0113 100%);
	border-radius: 0 20px 20px 0;
	color: #fff;
	text-align: center;
	font-size: 12px;
	overflow: hidden;
}

.coupon-user-item .content {
	width: 100%;
	height: 90px;
	border-bottom: 1px dotted #f5f5f5;
	position: relative;
	z-index: 2;
}

.coupon-user-item .content .coupon-detail {
	display: flex;
	justify-content: space-between;
	padding: 0 15px 0 20px;
}

.coupon-user-item .content .coupon-detail > view {
	height: 90px;
	display: flex;
	justify-content: center;
	align-items: center;
}

.coupon-user-item .content .coupon-detail > view:first-child {
	color: #e21422;
	padding-top: 20px;
	width: 30%;
}

.coupon-user-item .content .coupon-detail > view:first-child > text:first-child {
	font-size: 28px;
}

.coupon-user-item .content .coupon-detail > view:first-child > text:last-child {
	font-size: 16px;
	padding: 9px 0 0;
}

.coupon-user-item .coupon-detail > view:nth-child(2) {
	flex-direction: column;
	padding-top: 5px;
}

.coupon-user-item .coupon-detail > view:nth-child(2) > view {
	width: 100%;
}

</style>
